home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / mflzt.exe / lha / MFLTIME.H < prev    next >
C/C++ Source or Header  |  1989-11-02  |  9KB  |  211 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*  MFLTIME Header file                                                 */
  4. /*                                                                      */
  5. /*  Function prototypes for time-related functions.                     */
  6. /*                                                                      */
  7. /*  Copyright 1989 by Robert B. Stout dba MicroFirm                     */
  8. /*  All rights reserved                                                 */
  9. /*                                                                      */
  10. /*  Copyright 1986, 1987 by S.E. Margison                               */
  11. /*                                                                      */
  12. /*  Compiled by and for use with Zortech C/C++ 1.07 or later.           */
  13. /*                                                                      */
  14. /************************************************************************/
  15.  
  16. #ifndef MFLTIME_H
  17. #define MFLTIME_H
  18.  
  19. #include <stdio.h>
  20. #include <time.h>
  21. #include <mfldefs.h>
  22.  
  23. #ifndef _Cdecl_
  24.  #if __ZTC__ > 0x107
  25.   #define CONST__ const
  26.   #ifdef __STDC__
  27.    #define _Cdecl_
  28.   #else
  29.    #define _Cdecl_ cdecl
  30.   #endif
  31.  #else
  32.   #define CONST__
  33.   #define _Cdecl_
  34.  #endif
  35. #endif
  36.  
  37. #if __ZTC__ > 0x107
  38.  #if __cplusplus
  39.   extern "C" {
  40.  #endif
  41. #endif
  42.  
  43. /************************************************************************/
  44. /*                                                                      */
  45. /*  Microsecond accuracy timing operations.                             */
  46. /*                                                                      */
  47. /************************************************************************/
  48.  
  49. typedef unsigned long uclock_t;
  50.  
  51. #define UCLK_TCK 1000000L /* Usec per second - replaces CLK_TCK         */
  52. #define usec_difftime(start,finish) (finish-start)
  53.  
  54. uclock_t _Cdecl_ usec_clock(void);
  55. void     _Cdecl_ restart_uclock(void);
  56. uclock_t _Cdecl_ usec_delay(uclock_t);
  57. LOGICAL  _Cdecl_ usec_timeout(uclock_t, uclock_t, uclock_t);
  58. void     _Cdecl_ msec_pause(long);
  59.  
  60. /************************************************************************/
  61. /*                                                                      */
  62. /*  ANSI functions                                                      */
  63. /*                                                                      */
  64. /************************************************************************/
  65.  
  66. #if __ZTC__ > 0x107
  67. size_t _Cdecl_ strftime(char *, size_t, const char *, const struct tm *);
  68. #else
  69. size_t _Cdecl_ strftime(char *, size_t, char *, struct tm *);
  70. #endif
  71.  
  72. /************************************************************************/
  73. /*                                                                      */
  74. /*  Time zone functions                                                 */
  75. /*                                                                      */
  76. /************************************************************************/
  77.  
  78. extern int  daylight;
  79. extern long timezone;
  80.  
  81. int tzset(void);
  82.  
  83. /************************************************************************/
  84. /*                                                                      */
  85. /*  Julian (scalar) date functions                                      */
  86. /*                                                                      */
  87. /************************************************************************/
  88.  
  89. long     _Cdecl_ ymd_to_julian (unsigned, unsigned, unsigned);
  90. void     _Cdecl_ julian_to_ymd (long, unsigned *, unsigned *, unsigned *);
  91. int      _Cdecl_ julian_to_wkday(long);
  92. char *   _Cdecl_ julian_to_dayname(long);
  93. unsigned _Cdecl_ julian_to_yrday(long);
  94. LOGICAL  _Cdecl_ julian_to_time(long, time_t *);
  95. LOGICAL  _Cdecl_ julian_to_tm(long, struct tm *);
  96. long     _Cdecl_ time_to_julian(time_t);
  97. long     _Cdecl_ tm_to_julian(struct tm *);
  98.  
  99. /************************************************************************/
  100. /*                                                                      */
  101. /*  Structures & functions for accessing file dates and times           */
  102. /*                                                                      */
  103. /************************************************************************/
  104.  
  105. #ifndef FTIME_DEF__
  106. #define FTIME_DEF__
  107.  
  108. struct ftime {
  109.         unsigned int ft_tsec  : 5;
  110.         unsigned int ft_min   : 6;
  111.         unsigned int ft_hour  : 5;
  112.         unsigned int ft_day   : 5;
  113.         unsigned int ft_month : 4;
  114.         unsigned int ft_year  : 7;
  115.         } ;
  116.  
  117. int     _Cdecl_ getftime(int, struct ftime *);
  118. int     _Cdecl_ setftime(int, struct ftime *);
  119. int     _Cdecl_ touch(char *);
  120. void    _Cdecl_ get_filetime(struct tm *, int);
  121.  
  122. #endif /* FTIME_DEF__ */
  123.  
  124. /************************************************************************/
  125. /*                                                                      */
  126. /*  Misc functions                                                      */
  127. /*                                                                      */
  128. /************************************************************************/
  129.  
  130. void    _Cdecl_ installtick(int *),
  131.         _Cdecl_ removetick(void),
  132.         _Cdecl_ gtodsub(FILE *),
  133.         _Cdecl_ gtodstr(char *);
  134.  
  135. int     _Cdecl_ daynum(int, int, int),
  136.         _Cdecl_ isleap(unsigned),
  137.         _Cdecl_ weekday(int, int, int);
  138.  
  139. char  * _Cdecl_ monthis(int),
  140.       * _Cdecl_ wkdayname(int);
  141.  
  142. /************************************************************************/
  143. /*                                                                      */
  144. /*  Alternative file date and time functions                            */
  145. /*                                                                      */
  146. /************************************************************************/
  147.  
  148. struct DOS_TIME
  149. {
  150.         unsigned int ss : 5;
  151.         unsigned int mm : 6;
  152.         unsigned int hh : 5;
  153. } ;
  154.  
  155. struct DOS_DATE
  156. {
  157.         unsigned int da : 5;
  158.         unsigned int mo : 4;
  159.         unsigned int yr : 7;
  160. } ;
  161.  
  162. #if __ZTC__ > 0x107
  163.  #if __cplusplus
  164.   }
  165.  #endif
  166. #endif
  167.  
  168. #define dos_time(t) (*(struct DOS_TIME *)(&(t)))
  169. #define dos_date(t) (*(struct DOS_DATE *)(&(t)))
  170.  
  171. /*
  172. ** Demo code for using above structures
  173. */
  174.  
  175. #if 0
  176. *************************************************************************
  177. *                                                                       * 
  178. *       /*  Sample file date and time display.*/                        *
  179. *                                                                       *
  180. *       #include <stdio.h>                                              *
  181. *       #include <dos.h>                                                *
  182. *                                                                       *
  183. *       main(int argc, char *argv[])                                    *
  184. *       {                                                               *
  185. *               struct FIND *ffblk;                                     *
  186. *                                                                       *
  187. *               if (2 > argc)                                           *
  188. *               {                                                       *
  189. *                       puts("\aUsage: SHOWDATE filename[.ext]");       *
  190. *                       exit(1);                                        *
  191. *               }                                                       *
  192. *               if (!(ffblk = findfirst(argv[1], 0xff)))                *
  193. *               {                                                       *
  194. *                       printf("\aCant find %s\n", argv[1]);            *
  195. *                       exit(2);                                        *
  196. *               }                                                       *
  197. *               printf("File date is %d-%d-%d\n",                       *
  198. *                       dos_date(ffblk->date).mo,